(define pcurve_view "")
(define pcurve_ro "")
(define ref_pcurve_ps "")

(define face-pcurve (lambda ()
	(let	(
				(picked_face (part:selection))
			)
	(if (>(length picked_face) 0)
	(begin
		(define picked_face (car picked_face))
		(if (face? picked_face)
		(begin
			(if (not (view? pcurve_view))
				(begin
					(set! pcurve_view (view:gl 1050 0 500 500))
					(view:detach pcurve_view)
				)
			)
			(if (ro? pcurve_ro)
				(ro:erase pcurve_ro pcurve_view)				
			)
			(set! pcurve_ro (ro:face-pcurves picked_face))
			(ro:erase pcurve_ro)
			(ro:display pcurve_ro pcurve_view)
			(top pcurve_view)
			(zoom-all pcurve_view)
			)
			(display "FACE selection expected.\n")
		)
	)
	(display "Nothing picked.\n")
	)
	)
	)
)

(define pcurve_ps
	(lambda (n)
		(cond 
			((equal? n "EndPick") 
				(face-pcurve)
			)
		)
	)
)

(define show-pcurves
	(lambda (on-off)
	(if on-off
		(begin
			(display "Turning on pcurve display.  Pick a face to show the pcurves.\n")
			(set! ref_pcurve_ps (part:add-picksubscriber-script "pcurve_ps"))
		)
		(begin
			(display "Turning off pcurve display.\n")
			(part:remove-picksubscriber ref_pcurve_ps)
		)
	)
))
